/**
 * 时间复杂度：O(N^1.25) -- O(N^1.5) 记个O(N^1.3)
 * 空间复杂度：O(1)
 * 稳定性：不稳定
 */

public class ShellSort {
    public static void shellSort(int[] array) {
        int gap = array.length;
        while(gap > 1) {
            gap /= 2;
            shell(array,gap);
        }
    }

    public static void shell(int[] array, int gap) {
        for(int i = gap; i < array.length; i++) {
            int tmp = array[i];
            int j = i - gap;
            for(;j >= 0; j -= gap) {
                //此处为稳定，如果加个等于就变为不稳定了
                if(array[j] > tmp) {
                    array[j+gap] = array[j];
                }else {
                    //array[j+1] = tmp;
                    break;
                }
            }
            array[j+gap] = tmp;
        }
    }
}
